var path = require('path');

//cnpm i html-webpack-plugin -D
var htmlWebpackPlugin = require('html-webpack-plugin')

const VueLoaderPlugin = require('vue-loader/lib/plugin')


//当以命令行形式运行webpack或webpack-dev-server时候，根据配置文件打包

module.exports = {
    entry: path.join(__dirname, './src/main.js'),
    output: {
        path: path.join(__dirname, './dist'),
        filename: 'bundle.js'
    },
    plugins: [ //插件
        new htmlWebpackPlugin({
            template: path.join(__dirname, './src/index.html'),
            filename: 'index.html'
        }),
        new VueLoaderPlugin()
    ],
    module: { //配置第三方规则
        rules: [
            { test: /\.css$/, use: ['style-loader', 'css-loader'] },
            { test: /\.less$/, use: ['style-loader', 'css-loader', 'less-loader'] },
            { test: /\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader'] },
            //处理图片路径的loader
            //limit给定分值是图片的大小，单位byte，如果引用的图片大于或等于给定的limit值，则不会转为base64格式字符串
            // 如果图片小于给定的limit值，则不会转为八色64格式的值
            { test: /\.(jpg|png|gif|bmp|jpeg)$/, use: 'url-loader?limit=10000&name=[hash:8]-[name].[ext]' },
            //这是处理字体文件的loader配置
            { test: /\.(ttf|eot|svg|woff|woff2)$/, use: 'url-loader' },
            //js文件转换
            { test: /\.js$/, use: 'babel-loader', exclude: /node_modules/ },
            //处理.vue文件
            {test:/\.vue$/,use:'vue-loader'}
        ]

    },
    resolve: {
        alias: { //设置修改vue被导入的路径
            // "vue$": "vue/dist/vue.js"
        }
    }
}